<%--
  Created by IntelliJ IDEA.
  User: d11yu
  Date: 2022/4/14
  Time: 11:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<div id="page_nav">
    <c:if test="${page.pn>1}">
        <a href="${page.urlAction}&pn=1">首页</a>
        <a href="${page.urlAction}&pn=${page.pn-1}">上一页</a>
    </c:if>
    <c:choose>
        <%--情况 1:如果总页码小于等于5的情况，页码的范围是：1-总页码--%>
        <c:when test="${page.pt <= 5}">
            <c:set scope="request" var="begin" value="1"/>
            <c:set scope="request" var="end" value="${page.pt}"/>
        </c:when>
        <%--情况2:总页码大于5的情况--%>
        <c:when test="${page.pt > 5}">
            <c:choose>
                <c:when test="${page.pn <= 3}">
                    <c:set scope="request" var="begin" value="1"/>
                    <c:set scope="request" var="end" value="${page.pt}"/>
                </c:when>
                <c:when test="${page.pn >= page.pt - 4}">
                    <c:set scope="request" var="begin" value="${page.pt - 4}"/>
                    <c:set scope="request" var="end" value="${page.pt}"/>
                </c:when>
                <c:otherwise>
                    <c:set scope="request" var="begin" value="${page.pn - 2}"/>
                    <c:set scope="request" var="end" value="${page.pn + 2}"/>
                </c:otherwise>
            </c:choose>
        </c:when>
    </c:choose>
    <c:forEach begin="${begin}" end="${end}" var="i">
        <c:if test="${i == page.pn}">
            【${i}】
        </c:if>
        <c:if test="${i != page.pn}">
            <a href="${page.urlAction}&pn=${i}">${i}</a>
        </c:if>
    </c:forEach>
    <c:if test="${page.pn<page.pt}">
        <a href="${page.urlAction}&pn=${page.pn+1}">下一页</a>
        <a href="${page.urlAction}&pn=${page.pt}">末页</a>
    </c:if>
    共${page.pt}页，${page.ect}条记录 到第<input value="${page.pn}" name="pn" id="pn_input"/>页
    <input id="goto" type="button" value="确定">
</div>
